//package cn.kgc.springcloud2038.order80.controller;
//
//import cn.kgc.springcloud2038.api.pojo.CommonResult;
//import cn.kgc.springcloud2038.api.pojo.Payment;
//import cn.kgc.springcloud2038.order80.service.LoadBalancer;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.client.discovery.DiscoveryClient;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.client.RestTemplate;
//
//import javax.annotation.Resource;
//import java.net.URI;
//import java.util.List;
//
//@RestController
//public class OrderController {
//    public static final String PaymentSrv_URL = "http://localhost:8001";
//
//    @Autowired
//    private RestTemplate restTemplate;
//    @Resource
//    private DiscoveryClient discoveryClient;
//
//    @Resource
//    private LoadBalancer loadBalancer;
//
//
//    @PostMapping("/consumer/payment/create") //客户端用浏览器是get请求，但是底层实质发送post调用服务端8001
//    public CommonResult create(@RequestBody Payment payment)
//    {
//        return restTemplate.postForObject("http://CLOUD-PAYMENT-SERVICE/payment/create",payment,CommonResult.class);
//    }
//
//
//    @GetMapping("/consumer/payment/get/{id}")
//    public CommonResult getPayment(@PathVariable Long id)
//    {
////        return restTemplate.getForObject("http://CLOUD-PAYMENT-SERVICE/payment/get/"+id, CommonResult.class);
//        List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVICE");
//
//        if(instances == null || instances.size()<=0) {
//            return null;
//        }
//        ServiceInstance serviceInstance = loadBalancer.instances(instances);
//        URI uri = serviceInstance.getUri();
//
//        return restTemplate.getForObject(uri+"/payment/get/"+id, CommonResult.class);
//    }
//
//
//
//}
